Vue Js query parameter from url:To retrieve a query parameter from a URL using Vue.js, you can use the built-in window.location.search property to access the query string.
First, you need to extract the query string from the URL using window.location.search. Then, you can use JavaScript to parse the query string and retrieve the value of the parameter you’re interested in. One way to do this is by splitting the query string by the & symbol, and then splitting each parameter by the = symbol.
How can I extract query parameters from a URL using Vue.js?
The code snippet you provided is using the URLSearchParams API to extract the value of the id query parameter from the URL.
Here’s a brief explanation of what’s happening in the code:
- The
window.location.searchproperty returns the query string portion of the URL, including the “?” character. In this case, it will be “?id=123”. - The
URLSearchParamsconstructor creates a new object that represents the query parameters in the URL. - The
urlParams.get('id')method retrieves the value of theidparameter from theURLSearchParamsobject. In this case, it will return the string “123”.
So, after running this code, the variable id will contain the value “123”.
Vue Js query parameter from url Example
// Assuming the URL is http://example.com/?id=123
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const id = urlParams.get('id'); // id = '123'


